from functools import wraps
from django.views.decorators.csrf import csrf_exempt
from common.utils.maestro_exceptions import MaestroException, ACCESS_DENIED


def check_auth(req):
    if not req.user_id:
        raise MaestroException(ACCESS_DENIED)


def token_required(func):
    @csrf_exempt
    @wraps(func)
    def _wrapped(req, *args, **kwargs):
        check_auth(req)
        return func(req, *args, **kwargs)
    return _wrapped
